package com.qf.md.unit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.common.PageParam;
import com.qf.common.PageVO;
import com.qf.entity.md.unit.MdUnitMeasure;
import com.qf.exception.CustomerException;
import com.qf.md.unit.dao.MdUnitMeasureDAO;
import com.qf.md.unit.param.UnitSearchParam;
import com.qf.md.unit.service.MdUnitMeasureService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MdUnitMeasureServiceImpl implements MdUnitMeasureService {
    @Resource
    private MdUnitMeasureDAO mdUnitMeasureDAO;
    @Override
    public PageVO<MdUnitMeasure> unitPage(UnitSearchParam unitSearchParam) {
        PageHelper.startPage(unitSearchParam.getPageNum(),unitSearchParam.getPageSize());
        List<MdUnitMeasure> list = mdUnitMeasureDAO.selectPage(unitSearchParam);
        PageInfo<MdUnitMeasure> pageInfos = new PageInfo<>(list);
        System.out.println(pageInfos);
        if (pageInfos != null){
            //PageVO 定向将一些垃圾年数据给过滤掉了，只传给前端有用的数据
            return new PageVO<>(pageInfos.getTotal(),pageInfos.getList());
        //{"total":16, "dataList": [{},{},...]}
        }
        return null;
    }

    @Override
    public int addMdUnitMeasure(MdUnitMeasure mdUnitMeasure) {
        if(mdUnitMeasure==null){
            throw  new CustomerException("参数为空");
        }
        mdUnitMeasureDAO.insertMdUnitMeasure(mdUnitMeasure);
        return 1;
    }

    @Override
    public int delMdUnitMeasure(Long mdUnitMeasure) {
        mdUnitMeasureDAO.delMdUnitMeasure(mdUnitMeasure);
        return 1;
    }

    @Override
    public int updateMdUnitMeasure(MdUnitMeasure mdUnitMeasure) {
        mdUnitMeasureDAO.updateMdUnitMeasure(mdUnitMeasure);
        return 1;
    }

    @Override
    public void delBatch(List<Long> ids) {
        mdUnitMeasureDAO.delBatch(ids);
    }

    @Override
    public List<MdUnitMeasure> select() {
        return mdUnitMeasureDAO.select();
    }


}
